package com.backend.system.service.manage;

import com.backend.system.beans.DeleteBatchReq;
import com.backend.system.beans.DeleteReq;
import com.backend.system.beans.user.*;
import com.backend.system.common.enums.ActionTypeEnum;
import com.backend.system.common.processor.ProcessorContext;
import com.backend.system.util.ManagerUtil;

/**
 * 用户管理
 *
 * @author backend-manage
 */
public class UserManage {

    /**
     * 用户登录
     *
     * @param req 请求入参
     * @return 响应
     */
    public static UserLoginVO userLogin(UserLoginReq req) {
        ProcessorContext<UserLoginReq> context = new ProcessorContext<>();
        context.setData(req);
        context.setAction(ActionTypeEnum.USER_LOGIN);
        return ManagerUtil.handle(context);
    }

    /**
     * 用户修改密码
     *
     * @param req 请求入参
     * @return 响应
     */
    public static Boolean userModifyPassword(UserModifyPasswordReq req) {
        ProcessorContext<UserModifyPasswordReq> context = new ProcessorContext<>();
        context.setData(req);
        context.setAction(ActionTypeEnum.USER_MODIFY_PASSWORD);
        return ManagerUtil.handle(context);
    }

    /**
     * 新增/修改用户
     *
     * @param req 请求入参
     * @return 响应
     */
    public static Boolean addOrUpdate(UserAddOrUpdateReq req) {
        ProcessorContext<UserAddOrUpdateReq> context = new ProcessorContext<>();
        context.setData(req);
        context.setAction(ActionTypeEnum.USER_ADD_OR_UPDATE);
        return ManagerUtil.handle(context);
    }

    /**
     * 用户分配角色
     *
     * @param req 请求入参
     * @return 响应
     */
    public static Boolean grantRoles(UserGrantRolesReq req) {
        ProcessorContext<UserGrantRolesReq> context = new ProcessorContext<>();
        context.setData(req);
        context.setAction(ActionTypeEnum.USER_GRANT_ROLES);
        return ManagerUtil.handle(context);
    }

    /**
     * 删除用户
     *
     * @param req 请求入参
     * @return 响应
     */
    public static Boolean delete(DeleteReq req) {
        ProcessorContext<DeleteReq> context = new ProcessorContext<>();
        context.setData(req);
        context.setAction(ActionTypeEnum.USER_DELETE);
        return ManagerUtil.handle(context);
    }

    /**
     * 批量删除用户
     *
     * @param req 请求入参
     * @return 响应
     */
    public static Boolean deleteBatch(DeleteBatchReq req) {
        ProcessorContext<DeleteBatchReq> context = new ProcessorContext<>();
        context.setData(req);
        context.setAction(ActionTypeEnum.USER_DELETE_BATCH);
        return ManagerUtil.handle(context);
    }
}
